knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)
library(tidyverse)
library(here)
library(janitor)
library(sf)
library(tmap)
This task draws on data from the Oil Spill Prevention and Response (OSPR) Incident Tracking database. The data are collected by OSPR Field Response Team members for Marine oil spills and by OSPR Inland Pollution Coordinators and Wardens for Inland incidents. An “incident”, for purposes of this database, is “a discharge or threatened discharge of petroleum or other deleterious material into the waters of the state.” This database is used to both inform the public of these incidents and assess the preparedness and responsiveness of agencies responsible for managing environmental damages including spills.
# Read in counties shapefile first
ca_counties_sf <- read_sf(here("data", "task1_data", "ca_counties", "CA_Counties_TIGER2016.shp")) %>%
clean_names() # to get names in lower snake case
# filtering for two variables of interest
ca_sub_sf <- ca_counties_sf %>%
select(county_name = name, land_area = aland)
# Now read in spill data
oil_spills <- read_sf(here("data", "task1_data", "ds394.shp")) %>%
clean_names() # to get names in lower snake case
This analysis creates two different maps to view the spatial distribution and concentration of oil spills at the county level throughout California. The severity or magnitude of these spills in not tracked in the data set used for this assesment.
#Setting coordinate reference system
# ca_sub_sf %>% st_crs() # This is 4326 ID
# oil_spills %>% st_crs() # This is 4296 ID
# Need to make oil spills same crs
spills_4326_sf <- st_transform(oil_spills, st_crs(ca_counties_sf))
# spills_4326_sf %>% st_crs()
# They seem to match now, silencing these so they don't show up in the knitted document.
# Exploratory quick plot to see how this looks together
#ggplot() +
#geom_sf(data = ca_counties_sf) +
#geom_sf(data = spills_4326_sf, size = 1, color = "red")
# Seems to look okay to me, lets tmap this
tmap_mode(mode = "view")
tm_shape(ca_sub_sf) +
tm_borders() +
tm_fill("land_area", title = "Land Area (meters squared)",
palette = "BuGn") +
tm_shape(spills_4326_sf) +
tm_dots(col = "cadetblue")